<?php

include 'connect.php';

$rows = [];
$sql = 'SELECT * FROM msg ORDER BY id DESC';
$data = $db->query($sql);
if($data){
	while ($r = $data->fetch_array(MYSQL_ASSOC)) {
	$rows[] = $r;
	}
}
?>


<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8"/>
		<title>留言板</title>
		<!-- <link rel="stylesheet" type="text/css" href="writebroad/style.css"> -->


		<style>
		.wrap{
			width: 300px;
			/*background: #ccc;*/
			margin: 0 auto;
		}
		.add .content{
			width: 298px;
			margin: 0;
			padding: 0;
		}
		.add .user{
			float: left;
		}
		.add .btn{
			float: right;
		}
		.msg{margin: 20px 0px;background: #ccc;}
		.msg .info{overflow: hidden;}
		.msg .user{float: left;color: blue;}
		.msg .time{float: right;}
		.msh .content{width: 100%;padding: 5px}
		</style>
	</head>

	<body>
		<div  class = "wrap">
			<div class="add">
			<form action="post.php" method="post">
			<textarea name='content' class="content" cols="50" rows="5"></textarea>
			<br/>

			<input name='user' calss="user" type="text"/>
			<input class="btn" type="submit" value="发表留言"/>
		</form>
		</div>
		<?php
		foreach ($rows as $row ) {
		?>
		<div class="msg">
			<div class="info">
				<span class="user"><?php echo $row['user'];?></span>
				<span class="time"><?php echo date('Y-m-d H:i:s',$row['time']);?></span>
			</div class="content">
			<div>
				<?php echo $row['content'];?>
			</div>
		</div>

		<?php
		}
		?>

		</div>
	</body>
</html>